import { Injectable } from '@angular/core';
import {FrameContext,BindingData,Repository} from '@farris/devkit';
import { BefRepository, ResponseInfo } from '@farris/bef';
import {  BeActionService, FormMessageService ,CommandService } from '@farris/command-services';
import { tap,switchMap } from 'rxjs/operators'

@Injectable()
export class SbssRyxxFrmControllerService {
  constructor(
        private frameContext:FrameContext,
    private beActionService: BeActionService,
    private messageService: FormMessageService,
        private commandService: CommandService
  ) {}

  /**
   * 启用审批
   * @remarks 
   * @returns 
   */
  qysp(id,mxId): any {
    const rep = this.frameContext.repository as BefRepository<any>;
    const repInfo = rep.restService.buildRequestInfo();

    const actionUri = 'qyqm';
    const body = {
      id: id,
      mxId:mxId,
      requestInfo: repInfo
    }

    const action$ = this.beActionService.invokeAction(actionUri, 'PUT', null, null, body);
    return action$.pipe(
      tap((responseInfo: ResponseInfo) => {
        this.messageService.info("签名已切换!");
        this.commandService.execute("rootviewmodelFilter1","root-component");
      }))
  }
}
